<template>
  <div class="photoinfo-container">
    <h3>{{photoinfo.title}}</h3>
    <p class="subtitle">
      <span>发表时间:{{photoinfo.add_time | dateFormat }}</span>
      <span>点击:{{photoinfo.click}}次</span>
    </p>
    <hr />
    <!-- 缩略图区域 -->
    <div class="thumbs">
      <vue-preview :slides="slide1"></vue-preview>
    </div>

    <!-- 图片内容区域 -->
    <div class="content">{{photoinfo.content}}</div>

    <!-- 评论子组件 -->
    <comment :id="this.id"></comment>
  </div>
</template>

<script>
import Comment from "./Comment.vue";
export default {
  data() {
    return {
      id: this.$route.params.id, //路由找到的id
      photoinfo: {}, //图片详情
      slide1: []
    };
  },
  created() {
    this.getPhotoInfo();
    this.getPhotoes();
  },
  methods: {
    getPhotoInfo() {
      //获取图片的详情
      this.$axios.get("../../json/imginfo.json").then(res => {
        for (let i = 0; i < res.data.length; i++) {
          //console.log(res.data[i]);
          if (this.id == res.data[i].id) {
            this.photoinfo = res.data[i];
            //console.log(this.photoinfo);
            break;
          }
        }
      });
    },
    getPhotoes() {
      this.$axios.get("../../json/photoes.json").then(res => {
        //console.log(res.data);
        res.data.forEach(item => {
          item.msrc = item.src;
          item.w = 600;
          item.h = 400;
        });
        this.slide1 = res.data;
        console.log(this.slide1);
      });
    }
  },
  components: {
    comment: Comment
  }
};
</script>

<style lang="scss">
.photoinfo-container {
  padding: 3px;
  h3 {
    color: #26a2ff;
    font-size: 15px;
    text-align: center;
    margin: 15px 0;
  }
}

.subtitle {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}
.content {
  font-size: 13px;
  line-height: 30px;
}

.thumbs .my-gallery {
  display: flex;
  flex-wrap: wrap;
}
.thumbs .my-gallery figure {
  display: inline-block;
  width: 30%;
  margin: 5px;
}
.thumbs .my-gallery figure img {
  width: 100%;
  height: 110px;
}
</style>